﻿using UnityEngine;
using System.Collections;

public class Choice1 : MonoBehaviour {
	// Use this for initialization
	void Start () {
        if (transform.parent.GetComponent<EventMsg>().m_EventChoice == EVENT_CHOICE.CHOICE_STATE)
        {
            GetComponent<UISprite>().spriteName = "NewspaperBtn1";
            transform.localPosition = new Vector3(0, -2f);
            GetComponent<UISprite>().width = 220;
            GetComponent<BoxCollider>().size = new Vector3(220, 100);
            GetComponent<UIButton>().normalSprite = GetComponent<UISprite>().spriteName;
        }
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    void OnClick()
    {
        switch (transform.parent.GetComponent<EventMsg>().m_strTimedEventID)
        {
            case "RiotComing":
                GameObject.Find("GameLogic").transform.FindChild("EnemySpawn").gameObject.SetActive(true);
                GameObject.Find("TopPanel").transform.FindChild("GameStatus").gameObject.SetActive(true);
                break;

            case "Retreat":
                GameObject.Find("Friends").GetComponent<DontDestroy>().Unparenting();
                Application.LoadLevel(2);
                Clock.iDay += 2;
                Clock.iHour = 7;
                break;

            case "Attack":
                break;

            case "SupplyBeCutOff":
                GameObject.Find("EventMgr").GetComponent<EventMgr>().EventMsgSend(29.0f, "SupplyBeCutOff_Restore");
                GameObject.Find("EventMgr").GetComponent<EventMgr>().SetTruckEventTimer(Random.Range(120.0f, 180.0f)); // random next truck coming till fix connection

                if (GameObject.Find("TruckEvent(Clone)"))
                    if(!GameObject.Find("TruckEvent(Clone)").GetComponent<TruckEvent>().bParking)
                        GameObject.Find("TruckEvent(Clone)").GetComponent<TruckEvent>().DestroyThisTruck();
                    else
                        GameObject.Find("TruckEvent(Clone)").GetComponent<TruckEvent>().m_bSetTimerOnce = true;

                break;

            case "SupplyBeCutOff_Restore":
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].gameObject.SetActive(true);
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].transform.FindChild("Main").FindChild("Unit").GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1);
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().UnitList.Add(GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].transform.FindChild("Main").FindChild("Unit").GetComponent<UnitStatus>());
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].transform.FindChild("Main").FindChild("Unit").GetComponent<UnitStatus>().m_unitData.objNameTag.gameObject.SetActive(true);
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList.RemoveAt(0);
                break;

            case "SupplyBeCutOff_Dead":
                Destroy(GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].gameObject);
                Destroy(GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].transform.FindChild("Main").FindChild("Unit").GetComponent<UnitStatus>().m_unitData.objNameTag.gameObject);
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList.RemoveAt(0);
                break;

            case "SupplyBeCutOff_Barely":
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].gameObject.SetActive(true);
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].transform.FindChild("Main").FindChild("Unit").GetComponent<SpriteRenderer>().color = new Color(1, 1, 1, 1);
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().UnitList.Add(GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].transform.FindChild("Main").FindChild("Unit").GetComponent<UnitStatus>());
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].transform.FindChild("Main").FindChild("Unit").GetComponent<UnitStatus>().m_unitData.objNameTag.gameObject.SetActive(true);
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].transform.FindChild("Main").FindChild("Unit").GetComponent<UnitStatus>().m_unitData.iCurrentHP = GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].transform.FindChild("Main").FindChild("Unit").GetComponent<UnitStatus>().m_unitData.iMaxHP / 5;
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList.RemoveAt(0);
                break;


            case "Volunteer_TurnEnemy":
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].tag = "Enemy";
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList[0].transform.FindChild("Main").FindChild("Unit").tag = "Enemy";
                GameObject.Find("SceneDataMgr").GetComponent<SceneDataMgr>().GoneToMissionUnitList.RemoveAt(0);
                break;
        }

        GameTime.TimeSpeed_Play();
        Destroy(transform.parent.gameObject);
    }
}
